/**
 * @FileName: ProductOrderService.java
 * @Author
 * @Description:
 * @Date 2016年5月23日 下午5:13:13
 * @CopyRight ZTE Corporation
 */
package cn.hpclub.server.service.product;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import cn.hpclub.server.model.GoodsOrder;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.aop.Before;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import cn.hpclub.server.constant.ClientApiConstant;
import cn.hpclub.server.constant.Constant;
import cn.hpclub.server.model.product.ProductOrder;
import cn.hpclub.server.util.HttpUtil;
import cn.hpclub.server.util.InterfaceUtil;
import cn.hpclub.server.util.QueryHelper;
import cn.hpclub.server.util.SystemConfigUtil;

public class ProductOrderService {
    private static final Logger logger = LoggerFactory.getLogger(ProductOrderService.class);
    private String dprUrlPrefix = SystemConfigUtil.getSystemConfig().getCmccHostPrefix();

    public static final ProductOrderService service = new ProductOrderService();


    public QueryHelper listQueryHelper(ConcurrentHashMap<String, String> searchInfo) {
        QueryHelper helper = new QueryHelper("SELECT IF(orgType.orgIDTmp || orgType2.orgIDTmp2,'是','否')AS is_accounts_manager," +
                " oc.class_name,o2.DisplayName as areaName,oi.order_id AS OrderID," +
                "  (CASE m.member_type" +
                " WHEN 1 THEN" +
                " '店长'" +
                " WHEN 2 THEN" +
                " '店员'" +
                " WHEN 3 THEN" +
                " '泛店员' ELSE '未知' END )AS member_type," +
                " (CASE order_status WHEN 5 THEN '新建' WHEN 10 THEN '成功' WHEN 15 THEN '失败' WHEN 20 THEN '异常' ELSE '未知' END) AS OrderStatus,product_name AS ProductName," +
                " product_sku_title AS ProductSkuTitle, imei AS IMEI, m.NAME AS SalesName, m.mobile AS SalesTel, m.emp_code," +
                " org.DisplayName, org.NumCode, customer_tel AS CustomerTel, unit_price as product_price, date_format( oi.create_time, '%Y-%m-%d %H:%i:%s' ) AS CreateTime," +
                " oi.org_id, city AS CityName, contract_id AS ContractId, contract_info AS ContractInfo ",
                " order_info oi LEFT JOIN order_items ot ON oi.order_id=ot.order_id LEFT JOIN member_org m ON oi.sales_id=m.id LEFT JOIN " +
                        " organization org ON org.id=m.org_id LEFT JOIN organization_class oc ON org.WebsiteId=oc.id LEFT JOIN organization o2 ON org.AreaCode=o2.id " +
                        " LEFT JOIN  (SELECT id AS orgIDTmp FROM `organization` WHERE (parentid = 54470 OR parentid IN(SELECT id FROM organization WHERE parentid = 54470 ) )" +
                        " )AS orgType ON m.org_id = orgType.orgIDTmp LEFT JOIN ( SELECT org.id AS orgIDTmp2, orgcls.WebsiteId AS WebsiteIdType " +
                        " FROM organization org, organization_class orgcls WHERE org.WebsiteId = orgcls.id AND org.enabled = 1 AND orgcls.enabled = 1 " +
                        " AND( orgcls.WebsiteId LIKE '6%' OR orgcls.WebsiteId = '1000' OR orgcls.WebsiteId = '4800'))AS orgType2 ON m.org_id = orgType2.orgIDTmp2 ");


        /*helper.addCondition("order_info.order_id = order_items.order_id");
        helper.addCondition("order_info.sales_id = member_org.id");
        helper.addCondition("org.id = member_org.org_id");
        helper.addCondition("order_info.order_id = order_items.order_id");*/

        helper.addCondition(searchInfo.containsKey("org_id") && StrKit.notBlank(searchInfo.get("org_id")), String.format("oi.org_id IN(%s) ", InterfaceUtil.getChlidOrgIdSql(Integer.parseInt(searchInfo.get("org_id")), Constant.MAX_ORG_LEVEL, true)));
        helper.addCondition(searchInfo.containsKey("order_id"), String.format("%s LIKE '%s%%' ", "oi.order_id", searchInfo.get("order_id")));
        if (searchInfo.containsKey("member_type") && Integer.parseInt(searchInfo.get("member_type")) > 0) {
            helper.addCondition(searchInfo.containsKey("member_type"), "m.member_type=" + searchInfo.get("member_type"));
        }
        helper.addCondition(searchInfo.containsKey("sales_tel"), String.format("%s LIKE '%s%%' ", "m.mobile", searchInfo.get("sales_tel")));
        helper.addCondition(searchInfo.containsKey("customer_tel"), String.format("%s LIKE '%s%%' ", "customer_tel", searchInfo.get("customer_tel")));
        helper.addCondition(searchInfo.containsKey("sales_city"), String.format("%s LIKE '%s%%' ", "city", searchInfo.get("sales_city")));
        helper.addCondition(searchInfo.containsKey("contract_id"), String.format("%s LIKE '%s%%' ", "imei", searchInfo.get("contract_id")));
        helper.addCondition(searchInfo.containsKey("start_date"), String.format("oi.create_time >= '%s 00:00:00' ", searchInfo.get("start_date")));
        helper.addCondition(searchInfo.containsKey("end_date"), String.format("oi.create_time <= '%s 23:59:59' ", searchInfo.get("end_date")));
        helper.addCondition(searchInfo.containsKey("creator"), String.format("ot.product_id IN (SELECT id FROM product WHERE creator=%s)", searchInfo.get("creator")));


        helper.addCondition(searchInfo.containsKey("order_status") && !"-1".equals(searchInfo.get("order_status")), "oi.order_status=?", searchInfo.get("order_status"));


        if (searchInfo.containsKey("isMgr") && !"2".equals(searchInfo.get("isMgr"))) {
            String isMgr = searchInfo.get("isMgr");
            if ("1".equalsIgnoreCase(isMgr)) {
                helper.addCondition("(!ISNULL(orgType.orgIDTmp) || !ISNULL(orgType2.orgIDTmp2))");
            } else {
                helper.addCondition(" (ISNULL(orgType.orgIDTmp) && ISNULL(orgType2.orgIDTmp2))");
            }
        }


        helper.addOrderProperty("oi.create_time", QueryHelper.ORDER_BY_DESC);
        return helper;
    }

    public QueryHelper listSnapshotQueryHelper(ConcurrentHashMap<String, String> searchInfo) {
        QueryHelper helper = new QueryHelper("SELECT is_accounts_manager,class_name,areaName,OrderID,(CASE member_type WHEN 1 THEN '店长' WHEN 2 THEN '店员' WHEN 3 THEN '泛店员' ELSE '未知' END )AS member_type,\n" +
                "(CASE OrderStatus WHEN 5 THEN '新建' WHEN 10 THEN '成功' WHEN 15 THEN '失败' WHEN 20 THEN '异常' ELSE '未知' END) AS OrderStatus,ProductName,ProductSkuTitle,IMEI,SalesName,SalesTel,emp_code,\n" +
                "DisplayName,NumCode,CustomerTel,product_price,date_format( CreateTime, '%Y-%m-%d %H:%i:%s' ) AS CreateTime,CityName,org_id,ContractId,ContractInfo", "snapshot_goods_order");

        //根据登录账户所属机构，来过滤显示的内容，比如成都地区的账号就只能看到成都地区的销售情况
        helper.addCondition(searchInfo.containsKey(GoodsOrder.ORG_ID) && StrKit.notBlank(searchInfo.get(GoodsOrder.ORG_ID)), String.format("%s IN(%s) ", GoodsOrder.ORG_ID, InterfaceUtil.getChlidOrgIdSql(Integer.parseInt(searchInfo.get(GoodsOrder.ORG_ID)), Constant.MAX_ORG_LEVEL, true)));
        helper.addCondition(searchInfo.containsKey("order_id"), String.format("%s LIKE '%s%%' ", GoodsOrder.ORDERID, searchInfo.get("order_id")));
        if (searchInfo.containsKey(GoodsOrder.MEMBER_TYPE) && Integer.parseInt(searchInfo.get(GoodsOrder.MEMBER_TYPE)) > 0) {
            helper.addCondition(searchInfo.containsKey(GoodsOrder.MEMBER_TYPE), GoodsOrder.MEMBER_TYPE + "=" + searchInfo.get(GoodsOrder.MEMBER_TYPE));
        }
        helper.addCondition(searchInfo.containsKey("sales_tel"), String.format("%s LIKE '%s%%' ", GoodsOrder.SALESTEL, searchInfo.get("sales_tel")));
        helper.addCondition(searchInfo.containsKey("customer_tel"), String.format("%s LIKE '%s%%' ", GoodsOrder.CUSTOMERTEL, searchInfo.get("customer_tel")));
        helper.addCondition(searchInfo.containsKey("sales_city"), String.format("%s LIKE '%s%%' ", GoodsOrder.CITYNAME, searchInfo.get("sales_city")));
        //前端传的是contract_id字段，但是显示是imei，后端也配合传imei
        helper.addCondition(searchInfo.containsKey("contract_id"), String.format("%s LIKE '%s%%' ", GoodsOrder.IMEI, searchInfo.get("contract_id")));
//        helper.addCondition(searchInfo.containsKey("contract_id"), String.format("%s LIKE '%s%%' ", GoodsOrder.CONTRACTID, searchInfo.get("contract_id")));
        helper.addCondition(searchInfo.containsKey("start_date"), String.format("%s >= '%s 00:00:00' ", GoodsOrder.CREATETIME, searchInfo.get("start_date")));
        helper.addCondition(searchInfo.containsKey("end_date"), String.format("%s <= '%s 23:59:59' ", GoodsOrder.CREATETIME, searchInfo.get("end_date")));
        helper.addCondition(searchInfo.containsKey("creator"), String.format("%s IN (SELECT id FROM product WHERE creator=%s)", GoodsOrder.PRODUCT_ID, searchInfo.get("creator")));


        helper.addCondition(searchInfo.containsKey("order_status") && !"-1".equals(searchInfo.get("order_status")), GoodsOrder.ORDERSTATUS + "=?", searchInfo.get("order_status"));


        if (searchInfo.containsKey("isMgr") && !"2".equals(searchInfo.get("isMgr"))) {
            String isMgr = searchInfo.get("isMgr");
            if ("1".equalsIgnoreCase(isMgr)) {
                helper.addCondition("is_accounts_manager='是'");
            } else {
                helper.addCondition("is_accounts_manager='否'");
            }
        }


        helper.addOrderProperty(GoodsOrder.CREATETIME, QueryHelper.ORDER_BY_DESC);
        return helper;
    }

    @Deprecated//改用QueryHelper实现
    public String getSqlSelect() {
        return "SELECT order_info.order_id AS OrderID," +
                "  (CASE member_org.member_type" +
                " WHEN 1 THEN" +
                " '店长'" +
                " WHEN 2 THEN" +
                " '店员'" +
                " WHEN 3 THEN" +
                " '泛店员' ELSE '未知' END )AS member_type," +
                " (CASE order_status WHEN 5 THEN '新建' WHEN 10 THEN '成功' WHEN 15 THEN '失败' WHEN 20 THEN '异常' ELSE '未知' END) AS OrderStatus,product_name AS ProductName, product_sku_title AS ProductSkuTitle, imei AS IMEI, member_org.NAME AS SalesName, member_org.mobile AS SalesTel, member_org.emp_code, org.DisplayName, org.NumCode, customer_tel AS CustomerTel, unit_price as product_price, date_format( order_info.create_time, '%Y-%m-%d %H:%i:%s' ) AS CreateTime, order_info.org_id, city AS CityName, contract_id AS ContractId, contract_info AS ContractInfo ";
    }

    @Deprecated//改用QueryHelper实现
    public String getSqlFilter(ConcurrentHashMap<String, String> searchInfo) {
        String sqlExceptSelect = " FROM order_info, order_items, member_org, organization org WHERE order_info.order_id = order_items.order_id AND order_info.sales_id = member_org.id AND org.id = member_org.org_id  ";

        for (Entry<String, String> item : searchInfo.entrySet()) {
            sqlExceptSelect += appendQueryFilter(item);
        }
        sqlExceptSelect += " ORDER BY order_info.create_time DESC";

        return sqlExceptSelect;
    }

    /**
     * @Title: buildQuery
     * @Description:追加查询条件
     */
    private String appendQueryFilter(Entry<String, String> item) {
        StringBuilder sb = new StringBuilder();
        String value = item.getValue();
        switch (item.getKey()) {
            case "org_id":
                sb.append(getSubOrgIdFilter(value));
                break;
            case "order_id":
                sb.append(getAndLikeFilter("order_info.order_id", value));
                break;
            case "member_type":
                if (Integer.parseInt(value.toString()) > 0) {
                    sb.append(" AND member_org.member_type=" + value);
                }
                sb.append(" ");
                break;
            case "sales_tel":
                sb.append(getAndLikeFilter("member_org.mobile", value));
                break;
            case "customer_tel":
                sb.append(getAndLikeFilter("customer_tel", value));
                break;
            case "sales_city":
                sb.append(getAndLikeFilter("city", value));
                break;
            case "contract_id":
                sb.append(getAndLikeFilter("contract_id", value));
                break;
            case "start_date":
                sb.append(getStartTimeFilter(item.getValue()));
                break;
            case "end_date":
                sb.append(getEndTimeFilter(item.getValue()));
                break;
            case "creator":
                sb.append(getCreatorFilter(value));
                break;
            default:
                break;
        }
        return sb.toString();
    }

    /**
     * @Title: getCreatorFilter
     * @Description:获取创建者查询条件
     */
    private String getCreatorFilter(String value) {
        return String.format(" AND order_items.product_id IN (SELECT id FROM product WHERE creator=%s) ", value);
    }

    /**
     * @Title: getSubOrgIdFilter
     * @Description:获取机构和子机构查询条件
     */
    private String getSubOrgIdFilter(String value) {
        if (!StrKit.isBlank(value)) {
            return String.format(" AND order_info.org_id IN(%s) ",
                    InterfaceUtil.getChlidOrgIdSql(Integer.parseInt(value), Constant.MAX_ORG_LEVEL, true));
        }
        return "";
    }

    /**
     * @Title: getEndTimeFilter
     * @Description:获取开始时间查询条件
     */
    private String getEndTimeFilter(String value) {
        return String.format(" AND order_info.create_time <= '%s 23:59:59' ", value);
    }

    /**
     * @Title: getStartTimeFilter
     * @Description:获取结束时间查询条件
     */
    private String getStartTimeFilter(String value) {
        return String.format(" AND order_info.create_time >= '%s 00:00:00' ", value);
    }

    /**
     * @Title: getAndLikeFilter
     * @Description:获取KeyName和value模糊查询条件
     */
    private String getAndLikeFilter(String keyName, String value) {
        return String.format(" AND %s LIKE '%s%%' ", keyName, value);
    }

    /**
     * @Title: getAndLikeFilter
     * @Description:获取KeyName和value模糊查询条件
     */

    public void saveProductOrderToBOSS(ProductOrder order)
            throws SaveProductOrderToBOSSException, SaveProductOrderToBOSSFail {
        String resultStr = "";

        try {
            resultStr = sendProdOrderToBOSS(order.getLogin_no(), order.getPhone_no(), order.getAct_id(),
                    order.getMeans_id(), order.getGroup_id(), order.getResource_no(),
                    order.getBatch_no());
            logger.debug("BOSS系统返回的商品订单详情：" + resultStr);
        } catch (Exception e) {
            e.printStackTrace();
            throw new SaveProductOrderToBOSSException("商品订单提交到BOSS系统异常");
        }

        if (StrKit.isBlank(resultStr)) {
            throw new SaveProductOrderToBOSSException("商品订单提交到BOSS系统异常,返回数据为空");
        }

        try {
            JSONObject bossJson = new JSONObject(resultStr);
            String resCode = bossJson.getString("resCode");
            // 查询到有数据的情况
            if ("0000000".equals(resCode)) {
                JSONObject outData = bossJson.getJSONObject("outData");
                String passFlag = outData.getString("PASS_FLAG");

                if ("Y".equals(passFlag)) {
                    String orderId = outData.getString("ORDER_ID");
                    String createAccept = outData.get("CREATE_ACCEPT").toString();

                    order.setBoss_order_id(orderId);
                    order.setCreate_accept(createAccept);
                    // 状态为提交订单成功
                    order.setOrder_status("10");
                } else {
                    // 状态为提交订单失败
                    order.setOrder_status("15");
                    String failMsg = "订单提交到BOSS系统失败";
                    // 解析失败原因
                    JSONObject MEAN_ALL = outData.getJSONObject("MEAN_ALL");
                    if ("N".equals(MEAN_ALL.getString("PASS_FLAG"))) {
                        JSONArray LIMIT_INFO = MEAN_ALL.getJSONArray("LIMIT_INFO");
                        for (int i = 0; i < LIMIT_INFO.length(); i++) {
                            JSONObject item = (JSONObject) LIMIT_INFO.get(i);
                            if ("N".equals(item.getString("PASS_FLAG"))) {
                                failMsg = item.getString("NOTE");
                                break;
                            }
                        }
                    }
                    throw new SaveProductOrderToBOSSFail(failMsg);
                }
            } else {
                String resMsg = bossJson.getString("resMsg");
                throw new SaveProductOrderToBOSSException(resMsg);
            }
        } catch (JSONException e) {
            throw new SaveProductOrderToBOSSException("BOSS系统返回数据解析异常");
        }
    }

    /**
     * @param order
     * @return boolean
     * @throws SaveProductOrderException
     * @Title: saveProductOrder
     * @Description:两张表，作为事务处理
     */
    @Before(Tx.class)
    public void saveProductOrderToDZG(ProductOrder order) throws SaveProductOrderException {
        // save order_info
        if (!saveOrderInfo(order)) {
            throw new SaveProductOrderException("保存商品订单失败");
        }
        // save order_item
        if (!saveOrderItem(order)) {
            throw new SaveProductOrderException("保存商品订单 item 失败");
        }
    }

    private boolean saveOrderInfo(ProductOrder info) {
        String sql = " insert into order_info "
                + " (order_id,sales_id,org_id,create_time,imei,customer_tel,city,total_price,customer_name,order_status,operated_by,operated_time) "
                + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";

        List<Object> paras = new ArrayList<Object>();
        paras.add(info.getOrder_id());
        paras.add(info.getSales_id());
        paras.add(info.getOrg_id());
        paras.add(new Date()); // BOSS没有返回订单日期，写DZG服务器日期
        paras.add(info.getImei());
        paras.add(info.getCustomer_tel());
        paras.add(info.getCity());
        paras.add(info.getTotal_price());
        paras.add(info.getCustomer_name());
        paras.add(5); // 初始订单状态为5 即新建
        paras.add(info.getSales_id());
        paras.add(new Date());

        int rc = Db.update(sql, paras.toArray());

        return (rc > 0) ? true : false;
    }

    private boolean saveOrderItem(ProductOrder item) {
        String sql = " insert into order_items "
                + " (order_id,product_id,product_name,product_title,product_sku_title,product_barcode,thumb,unit_price,rebate,amount,contract_id,contract_info) "
                + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?) ";

        List<Object> paras = new ArrayList<Object>();
        paras.add(item.getOrder_id());
        paras.add(item.getProduct_id());
        paras.add(item.getProduct_name());
        paras.add(item.getProduct_title());
        paras.add(item.getProduct_sku_title());
        paras.add(item.getProduct_barcode());
        paras.add(item.getThumb());
        paras.add(item.getUnit_price());
        paras.add(item.getRebate());
        paras.add(item.getAmount());
        paras.add(item.getContract_id());
        paras.add(item.getCustomer_name());
        int rc = Db.update(sql, paras.toArray());

        return (rc > 0) ? true : false;
    }

    public boolean updateOrderInfo(ProductOrder info) {
        String sql = " update order_info set boss_order_id = ? , create_accept = ?, order_status = ?, operated_by = ?, operated_time = ? where order_id = ? ";

        List<Object> paras = new ArrayList<Object>();
        paras.add(info.getBoss_order_id());
        paras.add(info.getCreate_accept());
        paras.add(info.getOrder_status());
        paras.add(info.getSales_id());
        paras.add(new Date());
        paras.add(info.getOrder_id());
        int rc = Db.update(sql, paras.toArray());

        return (rc > 0) ? true : false;
    }

    public static class SaveProductOrderException extends Exception {
        private static final long serialVersionUID = 6089550538298976818L;

        public SaveProductOrderException(String message) {
            super(message);
        }
    }

    public static class SaveProductOrderToBOSSException extends Exception {
        private static final long serialVersionUID = 8089556568298971818L;

        public SaveProductOrderToBOSSException(String message) {
            super(message);
        }
    }

    public static class SaveProductOrderToBOSSFail extends Exception {
        private static final long serialVersionUID = 1234556568298971818L;

        public SaveProductOrderToBOSSFail(String message) {
            super(message);
        }
    }

    private String sendProdOrderToBOSS(String login_no, String phone_no, String act_id, String means_id,
                                       String group_id, String resource_no, String batch_no) throws Exception {
        HashMap<String, Object> hm = new HashMap<String, Object>();
        hm.put("login_no", login_no);
        hm.put("phone_no", phone_no);
        hm.put("act_id", act_id);
        hm.put("means_id", means_id);
        hm.put("group_id", group_id);
        hm.put("resource_no", resource_no);
        hm.put("batch_no", batch_no);
        String result = HttpUtil.getHttpByPost(dprUrlPrefix + Constant.Url.CMCC_PROD_ORDER_CMIT, hm);

        return result;
    }

    public String getOrderList(String userId) {
        String sql = "SELECT info.order_id AS OrderId,item.product_name AS ProductName,item.product_sku_title AS Sku,item.unit_price AS Price, date_format( info.operated_time, '%Y-%m-%d %H:%i:%s' ) AS OperatedTime , thumb AS Picture_URL FROM order_info info, order_items item WHERE info.order_id = item.order_id AND info.sales_id=? ORDER BY OperatedTime DESC";
        List<Record> list = Db.find(sql, userId);
        JSONObject jo = new JSONObject();
        jo.put("ResultCode", 1000);
        jo.put("Message", "获取成功");
        JSONArray data = new JSONArray();
        String hostPrefix = SystemConfigUtil.getSystemConfig().getHostPrefix();
        for (Record record : list) {
            JSONObject item = new JSONObject();
            item.put("OrderId", record.getStr("OrderId"));
            item.put("ProductName", record.getStr("ProductName"));
            item.put("Sku", record.getStr("Sku"));
            item.put("Price", record.get("Price").toString());
            item.put("OperatedTime", record.get("OperatedTime").toString());
            item.put("Picture_URL", hostPrefix + record.getStr("Picture_URL"));
            data.put(item);
        }
        jo.put("Data", data);
        return jo.toString();
    }

    public String getOrderDetail(String orderId) {
        String sql = "SELECT info.order_id AS OrderId,item.product_name AS ProductName,item.product_sku_title AS Sku,item.unit_price AS Price, date_format( info.operated_time, '%Y-%m-%d %H:%i:%s' ) AS OperatedTime,imei,contract_id AS ContractId,contract_info AS ContractInfo, info.customer_tel AS CustomerTel,info.customer_name AS CustomerName, thumb AS Picture_URL FROM order_info info, order_items item WHERE info.order_id = item.order_id AND info.order_id=?";
        Record record = Db.findFirst(sql, orderId);
        JSONObject jo = new JSONObject();
        String hostPrefix = SystemConfigUtil.getSystemConfig().getHostPrefix();
        if (record != null) {
            jo.put("ResultCode", 1000);
            jo.put("Message", "获取成功");
            JSONObject data = new JSONObject();
            data.put("OrderId", record.getStr("OrderId"));
            data.put("ProductName", record.getStr("ProductName"));
            data.put("Sku", record.getStr("Sku"));
            data.put("Price", record.get("Price").toString());
            data.put("OperatedTime", record.get("OperatedTime").toString());
            data.put("imei", record.getStr("imei"));
            String contractId = record.getStr("ContractId");
            data.put("ContractId", contractId != null ? contractId : "");
            data.put("ContractInfo", record.getStr("ContractInfo"));
            data.put("CustomerTel", record.getStr("CustomerTel"));
            data.put("CustomerName", record.getStr("CustomerName"));
            data.put("Picture_URL", hostPrefix + record.getStr("Picture_URL"));
            jo.put("Data", data);
        } else {
            jo.put("ResultCode", ClientApiConstant.ResultCode.PARAM_ERROR);
            jo.put("Message", "未找到对应的订单详情，订单号" + orderId);
            jo.put("Data", "");
        }
        return jo.toString();
    }

}
